import java.awt.*;
import javax.swing.*;


public class MaiDrawu extends JPanel
{
	protected World w;
	protected Player p;
	protected int xpixel, ypixel, typeOf/*Living/environment/blocks/walls*/,subTypeOf/*for subclassification*/;
	//change to arraylists of array[4]s
	public MaiDrawu(World w, Player p)
	{
		this.w = w;
		this.p = p;
	}
	public void paintComponent(Graphics g)
	{
		renderBlox(g);
		renderPlayer(g);
	}
	protected void renderBG(Graphics g)
	{
		
	}
	protected void renderWalls(Graphics g)
	{
	}
	protected void renderBlox(Graphics g)
	{
		int centerX = 385 - (p.xcor%16);
		int centerY = 325 + (p.ycor%16) - 15;
		int blokX = -(int)(p.xcor/16);
		int blokY = -(int)(p.ycor/16);
		int beginX = (centerX)%16 - 16;
		int beginY = (centerY)%16 - 16;
		Image i = null;
		for(int k = beginX; k<800; k+=16)
		{
			for (int j = beginY; j<600; j+=16)
			{
				try
				{
					int boxXdev=(k-centerX)/16;
					int boxYdev=(j-centerY)/16;
					switch(w.foreground[-blokX+boxXdev][-blokY-boxYdev].type)
					{
					case Blocks.DIRT: i = new ImageIcon("Content\\Dirt2.png").getImage();break;
					case Blocks.SAND: i = new ImageIcon("Content\\Sand.png").getImage();break;
					default: i = null; break;
					}
				}
				catch(Exception e)
				{
					i = null;
				}
				g.drawImage(i,k,j,this);
			}
		}
	}
	protected void renderLiving(Graphics g)
	{
  
	}
	protected void renderPlayer(Graphics g)
	{
		Image i;
		if (p.left){i = new ImageIcon("Content\\Player_Left.png").getImage();}
		else {i = new ImageIcon("Content\\Player_Right.png").getImage();}
		g.drawImage(i,385,275,this);
	}
}
